package examples

import (
	"gitee.com/Cauchy_AQ/gokv"
	"gitee.com/Cauchy_AQ/gokv/utils"
)

func ExamplesBatch() {
	opts := gokv.DefaultOptions
	db, err := gokv.Open(&opts)
	defer db.Close()
	if err != nil {
		panic(err)
	}

	writrBatchOpts := gokv.DefaultWriteBatchOptions
	writrBatchOpts.MaxBatchNum = 256
	writrBatchOpts.SyncWrites = false
	wb := db.NewWriteBatch(&writrBatchOpts)

	for i := 0; i < 100; i++ {
		err = wb.Put(utils.GetTestValue(i), utils.GetTestValue(i))
		if err != nil {
			panic(err)
		}

		if i%5 == 0 {
			err = wb.Delete(utils.GetTestValue(i))
			if err != nil {
				panic(err)
			}
		}
	}
	if err := wb.Commit(); err != nil {
		panic(err)
	}
}
